import React from "react"
import { getHomeHotData_1, getHomeHotData_2 } from "../../../fetch/home"
import HotProduct from "../../../components/shop_components/HotProduct"
import * as util from "../../../components/util"

export default class HomeHot extends React.Component{
  constructor(){
    super();
    this.state = {
      hotData_1 :[],
      hotData_2 :[]
    }

  }

  componentDidMount(){
    // 本地读取城市
    let cityName = util.storage.get("city");
    getHomeHotData_1(cityName).then( data => { this.setState({hotData_1:data}) } );
    getHomeHotData_2(cityName).then( data => { this.setState({hotData_2:data}) } );
  }

  render(){
    let cityName = this.props.city;
    
    let { hotData_1,hotData_2 } = this.state;

    return(
      <div>
        {
          hotData_1 && hotData_1.length > 0 ?
          <HotProduct data={ hotData_1 } title="热销单品"/>
          : <div className="isLoading">正在加载数据...</div>
        }
        {
          hotData_2 && hotData_2.length > 0 ?
          <HotProduct data={ hotData_2 } title="热门商品"/>
          : <div className="isLoading">正在加载数据...</div>
        }
      </div>
    )
  }
}